//package com.atguigu.gulimall.ware.config;
//
//import com.alibaba.druid.pool.DruidDataSource;
//import com.zaxxer.hikari.HikariDataSource;
//import io.seata.rm.datasource.DataSourceProxy;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.boot.autoconfigure.jdbc.DataSourceProperties;
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Configuration;
//import org.springframework.util.StringUtils;
//
//import javax.sql.DataSource;
//
///**
// * @NAME: MySeataConfig
// * @USER: wjj
// * @DATE: 2023/12/2
// * @TIME: 14:07
// * @DAY_NAME_FULL: 星期六
// * @PROJECT_NAME: gulimall
// */
//@Configuration
//public class MySeataConfig {
//
//    @Autowired
//    DataSourceProperties dataSourceProperties;
//
////    @Bean
////    public DataSource dataSource1(DataSourceProperties dataSourceProperties) {
////
////        DruidDataSource dataSource = dataSourceProperties.initializeDataSourceBuilder().type(DruidDataSource.class).build();
////        if (StringUtils.hasText(dataSourceProperties.getName())) {
////            dataSource.setUsername(dataSourceProperties.getName());
////        }
////
////        return new DataSourceProxy(dataSource);
////    }
//    /**
//     * 需要将 DataSourceProxy 设置为主数据源，否则事务无法回滚
//     *
//     * @param dataSourceProperties
//     * @return
//     */
//    @Bean
//    public DataSource dataSource(DataSourceProperties dataSourceProperties) {
////        DruidDataSource build = dataSourceProperties.initializeDataSourceBuilder().type(DruidDataSource.class).build();
//        HikariDataSource dataSource = dataSourceProperties.initializeDataSourceBuilder().type(HikariDataSource.class).build();
//        if (StringUtils.hasText(dataSourceProperties.getName())) {
//            dataSource.setPoolName(dataSourceProperties.getName());
//
//        }
//
//        return new DataSourceProxy(dataSource);
//    }
//
//
//
//
////    @Value("${mybatis-plus.mapper-locations}")
////    private String mapperLocations;
////    @Bean
////    @ConfigurationProperties(prefix = "spring.datasource")
////    public DataSource druidDataSource(){
////        return new DruidDataSource();
////    }
////
////    @Bean
////    public DataSourceProxy dataSourceProxy(DataSource dataSource) {
////        return new DataSourceProxy(dataSource);
////    }
////
////    @Bean
////    public SqlSessionFactory sqlSessionFactoryBean(DataSourceProxy dataSourceProxy) throws Exception {
////        SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean();
////        sqlSessionFactoryBean.setDataSource(dataSourceProxy);
////        sqlSessionFactoryBean.setMapperLocations(new PathMatchingResourcePatternResolver().getResources(mapperLocations));
////        sqlSessionFactoryBean.setTransactionFactory(new SpringManagedTransactionFactory());
////        return sqlSessionFactoryBean.getObject();
////    }
//
//}
